import sys
from PyQt5 import QtCore
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton, QHBoxLayout


class MainWindow(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        button1 = QPushButton("Button1", self)
        button1.setObjectName("Button1")
        button2 = QPushButton("Button2", self)
        button2.setObjectName("Button2")


        #设置布局及窗口title和大小
        layout = QHBoxLayout()
        layout.addWidget(button1)
        layout.addWidget(button2)
        self.setLayout(layout)
        self.setWindowTitle("MainWindow Demo")
        self.resize(800, 600)


        QtCore.QMetaObject.connectSlotsByName(self)


    '''
        @PyQt5.QtCore.pyqtSlot(bool)
        def on_发送者对象名称_发射信号名称(self, parameter):
        pass
        
        参数：发送者对象名称是使用setObjectName为QObject对象设置的对象名称
        
        connectSlotsByName用于将QObject子孙对象的某些信号根据名称连接到某些QObject对象的相应槽函数
    '''

    @QtCore.pyqtSlot()
    def on_Button1_clicked(self):
        print("Button1 is clicked")

    @QtCore.pyqtSlot()
    def on_Button2_clicked(self):
        print("Button2 is clicked")

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()

    sys.exit(app.exec_())